package lib.quasar.widget.slide;

import android.content.Context;
import android.support.v4.view.MotionEventCompat;
import android.support.v4.widget.SlidingPaneLayout;
import android.util.AttributeSet;
import android.view.MotionEvent;

public class SwitchSlidingPaneLayout extends SlidingPaneLayout {

    public SwitchSlidingPaneLayout(Context context) {
        this(context, null);
    }

    public SwitchSlidingPaneLayout(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public SwitchSlidingPaneLayout(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    private boolean paneEnable = true;

    public void setPaneEnable(boolean paneEnable) {
        this.paneEnable = paneEnable;
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        switch (MotionEventCompat.getActionMasked(ev)){
            case MotionEvent.ACTION_MOVE:
                if(!paneEnable){
                    return false;
                }
        }
        return super.onInterceptTouchEvent(ev);
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        switch (MotionEventCompat.getActionMasked(ev)){
            case MotionEvent.ACTION_MOVE:
                if(!paneEnable){
                    return false;
                }
        }
        return super.onTouchEvent(ev);
    }

}